home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Demo / freeze / makefreeze.py < prev    next >
Encoding:
Text File  |  1994-10-03  |  1.8 KB  |  31 lines  |  [TEXT/R*ch]

  1. import marshal
  2.  
  3.  
  4. # Write a file containing frozen code for the modules in the dictionary.
  5.  
  6. header = """
  7. struct frozen {
  8.     char *name;
  9.     unsigned char *code;
  10.     int size;
  11. } frozen_modules[] = {
  12. """
  13. trailer = """\
  14.     {0, 0, 0} /* sentinel */
  15. };
  16. """
  17.  
  18. def makefreeze(outfp, dict):
  19.     done = []
  20.     mods = dict.keys()
  21.     mods.sort()
  22.     for mod in mods:
  23.         modfn = dict[mod]
  24.         try:
  25.             str = makecode(modfn)
  26.         except IOError, msg:
  27.             sys.stderr.write("%s: %s\n" % (modfn, str(msg)))
  28.             continue
  29.         if str:
  30.             done.append(mod, len(str))